package com.zxj.ds.mybatis.configuration;

import com.zxj.ds.mybatis.annotation.Saas2Dao;
import com.zxj.ds.mybatis.annotation.SaasDao;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.lang.annotation.Annotation;

/**
 * Created by Administrator on 2017/5/4.
 */
@Configuration
@AutoConfigureAfter(MyBatisConfiguration.class)
public class MyBatisScanner {

    /**
     * - 设置SqlSessionFactory；
     * - 设置dao所在的package路径，路径可以以逗号或者分号进行分隔设置多个
     * - 关联注解在dao类上的Annotation名字；
     * - 上面的注解可以不需要
     */
    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer1() throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory1");
        mapperScannerConfigurer.setBasePackage("com.zxj.ds.mybatis.dao.saas");
        //mapperScannerConfigurer.setAnnotationClass((Class<? extends Annotation>) Class.forName("com.zxj.ds.mybatis.annotation.SaasDao"));
        return mapperScannerConfigurer;
    }

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer2() {
        MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
        mapperScannerConfigurer.setSqlSessionFactoryBeanName("sqlSessionFactory2");
        mapperScannerConfigurer.setBasePackage("com.zxj.ds.mybatis.dao.saas2");
        //mapperScannerConfigurer.setAnnotationClass(Saas2Dao.class);
        return mapperScannerConfigurer;
    }
}
